package a66weding.com.jiehuntong.dao.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/7/27.
 */
public class TastDao  {

    private TastOpenHelper helper;

    public TastDao(Context context) {
        helper = new TastOpenHelper(context);

    }

    /**
     * 添加数据;
     * @param name
     * @param phone
     * @return
     */
    public long add(String name, String phone) {
        SQLiteDatabase db = helper.getWritableDatabase();
        // 其实就是一个map集合
        ContentValues values = new ContentValues();
        values.put("name", name);
        values.put("flag", phone);
        long result = db.insert("tast", null, values);
        db.close();
        return result;
    }


    /**
     * 查找全部
     *
     * @return
     */
    public List<TastBean> findAll() {
        SQLiteDatabase db = helper.getReadableDatabase();
        List<TastBean> list = new ArrayList<TastBean>();
        Cursor cursor = db.query("person",
                new String[] {  "name", "phone" }, null, null, null, null, null);
        while (cursor.moveToNext()) {
            String name = cursor.getString(0);
            String flag = cursor.getString(1);
            TastBean bean = new TastBean();
            bean.setFlag(flag);
            bean.setName(name);
            list.add(bean);
        }
        cursor.close();
        db.close();
        return null;
    }

    /**
     * 更新
     * @param name
     * @param flag
     * @return
     */
    public int  update(String name, String flag) {
        SQLiteDatabase db = helper.getWritableDatabase();
        ContentValues values = new ContentValues();
        values.put("flag",flag);
        int result  =db.update("task", values, "name=?", new String[] { name });
        db.close();
        return result;
    }

    /**
     * 查找某个字段的信息
     */

}
